package com.yangguang.huahui.mvp.presenter;

import com.yangguang.huahui.R;
import com.yangguang.huahui.entity.ChatStatus;
import com.yangguang.huahui.entity.ChatUser;
import com.yangguang.huahui.entity.HttpResult;
import com.yangguang.huahui.mvp.model.NewsModel;
import com.yangguang.huahui.mvp.view.ChatWindowView;
import com.yangguang.huahui.rx.RxManager;
import com.yangguang.huahui.rx.RxSubscriber;
import com.yangguang.huahui.utils.LogUtil;

import java.io.IOException;

import okhttp3.ResponseBody;

/**
 * Created by Administrator on 2017/3/14.
 */

public class ChatWindowPresenter extends BasePresenter<ChatWindowView>{
    NewsModel model;

    public ChatWindowPresenter() {
        model = new NewsModel();
    }
    public void getInfo(String forid, String toid){
        mSubscription = RxManager.getInstance().doSubscribe(model.getInfo(forid, toid), new RxSubscriber<ChatUser>(false) {
            @Override
            protected void _onNext(ChatUser chatUser) {
                mView.onInfo(chatUser);
            }

            @Override
            protected void _onError() {
                mView.onError();
            }
        });
    }
    public void sendMsg(String for_uid, String to_uid, String msg){
        mSubscription = RxManager.getInstance().doSubscribe(model.sendMsg(for_uid, to_uid, msg), new RxSubscriber<HttpResult>(false) {
            @Override
            protected void _onNext(HttpResult httpResult) {
                mView.onSendMsg(httpResult);
            }

            @Override
            protected void _onError() {
                mView.onError();
            }
        });
    }
    public void sendFeedMsg(String uid, String To_uid, String projectId, String type, String msg){
        mSubscription = RxManager.getInstance().doSubscribe(model.sendFeedMsg(uid, To_uid, projectId, type, msg), new RxSubscriber<HttpResult>(false) {
            @Override
            protected void _onNext(HttpResult httpResult) {
                mView.onSendFeedMsg(httpResult);
            }

            @Override
            protected void _onError() {
                mView.onError();
            }
        });
    }
    public void getStautu(String for_uid, String to_uid, String id){
        mSubscription = RxManager.getInstance().doSubscribe(model.getStatus(for_uid, to_uid, id), new RxSubscriber<ChatStatus>(false) {
            @Override
            protected void _onNext(ChatStatus chatStatus) {
                mView.onStatus(chatStatus);
            }

            @Override
            protected void _onError() {

            }
        });
    }

    public void addFriends(String for_uid, String to_uid, String id, String type){
        mSubscription = RxManager.getInstance().doSubscribe(model.addFriends(for_uid, to_uid, id, type), new RxSubscriber<ChatStatus>(false) {
            @Override
            protected void _onNext(ChatStatus chatStatus) {
                mView.onStatus(chatStatus);
            }

            @Override
            protected void _onError() {
                mView.onError();
            }
        });
    }
}
